import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Home',
    redirect: '/echarts/polarbar',
    component: () => import('@/views/home'),
    children: [
      {
        path: '/echarts/polarbar',
        name: 'PolarBar',
        component: () => import('@/views/home/echarts/polarBar')
      },
      {
        path: '/echarts/nestpie',
        name: 'NestPie',
        component: () => import('@/views/home/echarts/nestPie')
      },
      {
        path: '/echarts/legendcustom',
        component: () => import('@/views/home/echarts/legendCustom')
      },
      {
        path: '/echarts/hoverpie',
        name: 'HoverPie',
        component: () => import('@/views/home/echarts/hoverPie')
      },
      {
        path: '/echarts/graph',
        name: 'Graph',
        component: () => import('@/views/home/echarts/graph')
      },
      {
        path: '/echarts/gauge',
        name: 'Graph',
        component: () => import('@/views/home/echarts/gauge')
      },
      {
        path: '/csspreprocessor/less',
        name: 'Less',
        component: () => import('@/views/home/cssPreprocessor/less')
      },
      {
        path: '/event/click',
        name: 'EventDelivery',
        component: () => import('@/views/home/eventDelivery')
      },
      {
        path: '/router/params',
        name: 'RouterParams',
        component: () => import('@/views/home/router/params')
      },
      {
        path: '/vuex/state',
        name: 'Vuex',
        component: () => import('@/views/home/vuex')
      },
      {
        path: '/eslint',
        name: 'ESlint',
        component: () => import('@/views/home/eslint')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/reg')
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})

export default router
